package com.link.base.base.product.controller;

import com.link.base.base.product.model.ComputeQuotePartsCost;
import com.link.base.base.product.service.ComputeQuotePartsCostService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.model.BasicModel;
import com.link.core.basic.query.QueryParams;
import com.link.core.basic.service.BasicService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 成本信息汇总临时对象
 *
 * @date 2023-08-15 09:04:14
 */
@Controller
@RequestMapping("/link/computeQuotePartsCost")
public class ComputeQuotePartsCostController extends BasicController<ComputeQuotePartsCost> {

    private static final Logger logger = LogManager.getLogger(ComputeQuotePartsCostController.class);

    @Resource
    private ComputeQuotePartsCostService computeQuotePartsCostService;

    @Override
    public BasicService<ComputeQuotePartsCost> getBasicService() throws Exception {
        return computeQuotePartsCostService;
    }




    @RequestMapping({"/addSelectPartCost"})
    @ResponseBody
    public Map<String, Object> addSelectPartCost(@JsonParam ComputeQuotePartsCost entity,
                                                 HttpSession session,
                                                 HttpServletRequest request,
                                                 HttpServletResponse response) {
        HashMap result = new HashMap(4);

        try {
            if (null == entity.getPartsCostId()) {
                throw new RuntimeException("缺失参数!");
            }
            computeQuotePartsCostService.addSelectPartCost(entity);
            result.put("success", true);
            result.put("code", "200");
        } catch (Exception var8) {
            logger.error("BasicController捕获异常: ", var8);
            result.put("success", false);
            result.put("result", var8.getMessage());
            result.put("code", "400");
        }

        return result;
    }


    @RequestMapping({"/queryPickListPage"})
    @ResponseBody
    public Map<String, Object> queryPickListPage(@JsonParam QueryParams qps,
                                                 @JsonParam ComputeQuotePartsCost entity,
                                                 HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        HashMap result = new HashMap(8);

        try {
            qps.preDealSecurity(request);
            ComputeQuotePartsCost temp = BasicModel.transformClass(entity, qps);
            this.beforQueryAllOrExample(temp, request);
            this.beforQueryExample(temp, request);
            List<ComputeQuotePartsCost> list = computeQuotePartsCostService.queryPickListPage(temp);
            result.put("success", true);
            result.put("rows", list);
            result.put("total", getCount(temp, list.size()));
            result.put("code", "200");
        } catch (Exception var10) {
            logger.error("BasicController捕获异常: ", var10);
            result.put("success", false);
            result.put("rows", new ArrayList());
            result.put("result", var10.getMessage());
            result.put("code", "400");
        }

        return result;
    }

}
